using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACME.Northwind.DataTransfer;
using ACME.Northwind.Service.Interfaces;
using ACME.Northwind.MockProxy.EventArgs;

namespace ACME.Northwind.MockProxy
{
	/// <summary>
	/// The service implementation for Customer object
	/// </summary>
	public partial class CustomerService : ICustomerService
	{
		#region ICustomerService Members

		/// <summary>
		/// Run the mock for the select by the primary key
		/// </summary>
		public CustomerDTO SelectByPrimaryKey(string customerid)
		{
			CustomerPrimaryKeyEventArgs eventArgs = new CustomerPrimaryKeyEventArgs(customerid);
			this.OnMockCustomerSelectByPrimaryKey(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for select all
		/// </summary>
		public List<CustomerDTO> RunSelect()
		{
			CustomerRunSelectEventArgs eventArgs = new CustomerRunSelectEventArgs();
			this.OnMockCustomerRunSelect(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for select with LINQ
		/// </summary>
		public List<CustomerDTO> RunSelect(string linq)
		{
			CustomerRunSelectLINQEventArgs eventArgs = new CustomerRunSelectLINQEventArgs(linq);
			this.OnMockCustomerRunSelectLINQ(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for paged select
		/// </summary>
		public PagedQueryResults<CustomerDTO> RunSelect(int pageIndex, int pageSize, bool ascending, string sortColumn, string linq)
		{
			CustomerRunSelectPagedEventArgs eventArgs = new CustomerRunSelectPagedEventArgs(pageIndex, pageSize, ascending, sortColumn, linq);
			this.OnMockCustomerRunSelectPaged(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Return a list of related CustomerCustomerDemo objects
		/// </summary>
		public List<CustomerCustomerDemoDTO> GetCustomerCustomerDemoList(CustomerDTO item)
		{
			CustomerDTOEventArgs eventArgs = new CustomerDTOEventArgs(item);
			this.OnMockGetCustomerCustomerDemoList(eventArgs);
			List<CustomerCustomerDemoDTO> retval = new List<CustomerCustomerDemoDTO>();
			retval.AddRange(eventArgs.ReturnDTOList.Select(x => (CustomerCustomerDemoDTO)x));
			return retval;
		}

		/// <summary>
		/// Return a list of related Order objects
		/// </summary>
		public List<OrderDTO> GetOrderList(CustomerDTO item)
		{
			CustomerDTOEventArgs eventArgs = new CustomerDTOEventArgs(item);
			this.OnMockGetOrderList(eventArgs);
			List<OrderDTO> retval = new List<OrderDTO>();
			retval.AddRange(eventArgs.ReturnDTOList.Select(x => (OrderDTO)x));
			return retval;
		}

		/// <summary>
		/// Return a list of items by the City field
		/// </summary>
		public List<CustomerDTO> SelectByCity(CustomerDTO item, string city)
		{
			List<CustomerDTO> retval = new List<CustomerDTO>();
			CustomerDTOEventArgs eventArgs = new CustomerDTOEventArgs(item);
			this.OnMockSelectByCity(eventArgs);
			retval.AddRange(eventArgs.ReturnDTOList.Select(x => (CustomerDTO)x));
			return retval;
		}

		/// <summary>
		/// Persists a single item
		/// </summary>
		public bool Persist(CustomerDTO dto)
		{
			CustomerPersistEventArgs eventArgs = new CustomerPersistEventArgs(dto);
			this.OnMockCustomerPersist(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Persists a list
		/// </summary>
		public bool Persist(List<CustomerDTO> list)
		{
			CustomerPersistEventArgs eventArgs = new CustomerPersistEventArgs(list);
			this.OnMockCustomerPersist(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Delete a single item
		/// </summary>
		public bool Delete(CustomerDTO dto)
		{
			CustomerDeleteEventArgs eventArgs = new CustomerDeleteEventArgs(dto);
			this.OnMockCustomerDelete(eventArgs);
			return eventArgs.ReturnValue;
		}

		#endregion

		#region Customer Events

		partial void GetSelectByPrimaryKey();

		/// <summary>
		/// The event for the SelectByPrimaryKey method
		/// </summary>
		public event EventHandler<CustomerPrimaryKeyEventArgs> MockCustomerSelectByPrimaryKey;

		/// <summary>
		/// Raises the OnMockRegistrationCodeSelectByPrimaryKey event
		/// </summary>
		protected virtual void OnMockCustomerSelectByPrimaryKey(CustomerPrimaryKeyEventArgs e)
		{
			if (this.MockCustomerSelectByPrimaryKey != null)
				this.MockCustomerSelectByPrimaryKey(this, e);
		}

		/// <summary>
		/// The event for the RunSelect method
		/// </summary>
		public event EventHandler<CustomerRunSelectEventArgs> MockCustomerRunSelect;

		/// <summary>
		/// Raises the OnMockRunSelect event
		/// </summary>
		protected virtual void OnMockCustomerRunSelect(CustomerRunSelectEventArgs e)
		{
			if (this.MockCustomerRunSelect != null)
				this.MockCustomerRunSelect(this, e);
		}

		/// <summary>
		/// The event for the RunSelectLINQ method
		/// </summary>
		public event EventHandler<CustomerRunSelectLINQEventArgs> MockCustomerRunSelectLINQ;

		/// <summary>
		/// The event for the OnMockRunSelectLINQ method
		/// </summary>
		protected virtual void OnMockCustomerRunSelectLINQ(CustomerRunSelectLINQEventArgs e)
		{
			if (this.MockCustomerRunSelectLINQ != null)
				this.MockCustomerRunSelectLINQ(this, e);
		}

		/// <summary>
		/// The event for the RunSelectPaged method
		/// </summary>
		public event EventHandler<CustomerRunSelectPagedEventArgs> MockCustomerRunSelectPaged;

		/// <summary>
		/// The event for the OnMockRunSelectPaged method
		/// </summary>
		protected virtual void OnMockCustomerRunSelectPaged(CustomerRunSelectPagedEventArgs e)
		{
			if (this.MockCustomerRunSelectPaged != null)
				this.MockCustomerRunSelectPaged(this, e);
		}

		/// <summary>
		/// The event for the GetCustomerCustomerDemoList method
		/// </summary>
		public event EventHandler<CustomerDTOEventArgs> MockGetCustomerCustomerDemoList;

		/// <summary>
		/// The event for the OnMockGetCustomerCustomerDemoList method
		/// </summary>
		protected virtual void OnMockGetCustomerCustomerDemoList(CustomerDTOEventArgs e)
		{
			if (this.MockGetCustomerCustomerDemoList != null)
				this.MockGetCustomerCustomerDemoList(this, e);
		}

		/// <summary>
		/// The event for the GetOrderList method
		/// </summary>
		public event EventHandler<CustomerDTOEventArgs> MockGetOrderList;

		/// <summary>
		/// The event for the OnMockGetOrderList method
		/// </summary>
		protected virtual void OnMockGetOrderList(CustomerDTOEventArgs e)
		{
			if (this.MockGetOrderList != null)
				this.MockGetOrderList(this, e);
		}

		/// <summary>
		/// The event for the SelectByCity method
		/// </summary>
		public event EventHandler<CustomerDTOEventArgs> MockSelectByCity;

		/// <summary>
		/// The event for the OnMockSelectByCity method
		/// </summary>
		protected virtual void OnMockSelectByCity(CustomerDTOEventArgs e)
		{
			if (this.MockSelectByCity != null)
				this.MockSelectByCity(this, e);
		}

		/// <summary>
		/// The event for the Persist method
		/// </summary>
		public event EventHandler<CustomerPersistEventArgs> MockCustomerPersist;

		/// <summary>
		/// Raises the OnMockPersist event
		/// </summary>
		protected virtual void OnMockCustomerPersist(CustomerPersistEventArgs e)
		{
			if (this.MockCustomerPersist != null)
				this.MockCustomerPersist(this, e);
		}

		/// <summary>
		/// The event for the Delete method
		/// </summary>
		public event EventHandler<CustomerDeleteEventArgs> MockCustomerDelete;

		/// <summary>
		/// Raises the OnMockDelete event
		/// </summary>
		protected virtual void OnMockCustomerDelete(CustomerDeleteEventArgs e)
		{
			if (this.MockCustomerDelete != null)
				this.MockCustomerDelete(this, e);
		}

		#endregion

	}
}
